package test.org.dei.junit;


import java.util.ArrayList;

import org.dei.perla.context.*;
import org.dei.perla.parser.expressions.ConstantString;
import org.dei.perla.parser.util.PairValue;

import junit.framework.*;

public class ActiveIfTestJUNIT extends TestCase {



public void test() throws NotFoundException{
	CDT cdt = CDT.getDefault();
	DimensionStructure dim1 = new Dimension("dim1","root",null);
	cdt.addDimensionToCDT(dim1);
    Value val11= new ValueWhenBased("val11", "dim1","temp>4");
	Value val12= new ValueOnBased("val12", "dim1","viticoltore()");
	val11.setDimension(dim1);
	val12.setDimension(dim1);
	dim1.getValues().add(val11);
	dim1.getValues().add(val12);
	
	DimensionStructure dim2 = new Dimension("dim2", "root",null);
	cdt.addDimensionToCDT(dim2);
	Value val21= new ValueWhenBased("val21", "dim2","hum>10");
	Value val22= new ValueOnBased("val22", "dim2","vigna()");
	val21.setDimension(dim2);
	val22.setDimension(dim2);
	dim2.getValues().add(val21);
	dim2.getValues().add(val22);
	
	PairValue<ConstantString,ConstantString> pair = new PairValue<ConstantString,ConstantString>();
	pair.setFirst(new ConstantString("dim1"));
	pair.setSecond(new ConstantString("val11"));
	ArrayList<PairValue<ConstantString,ConstantString>> dimvalue= new ArrayList<PairValue<ConstantString,ConstantString>>();
	dimvalue.add(pair);
	
	
	pair = new PairValue<ConstantString,ConstantString>();
	pair.setFirst(new ConstantString("dim2"));
	pair.setSecond(new ConstantString("val22"));
	dimvalue.add(pair);
	
	

	ActiveIfClause active = new ActiveIfClause(dimvalue);
			
	assertEquals("dim1",active.getDimValue().get(0).getFirst().getName());
	assertEquals("val11",active.getDimValue().get(0).getSecond().getNome());
	assertEquals("dim2",active.getDimValue().get(1).getFirst().getName());
	assertEquals("val22",active.getDimValue().get(1).getSecond().getNome());
	
	assertTrue(cdt.getDimList().contains(dim1));
	assertTrue(cdt.getDimList().contains(dim2));
	assertTrue(cdt.getDimList().get(0).getValues().contains(val11));
	assertTrue(cdt.getDimList().get(0).getValues().contains(val12));
	assertTrue(cdt.getDimList().get(1).getValues().contains(val21));
	assertTrue(cdt.getDimList().get(1).getValues().contains(val22));
	
	assertEquals(cdt.getValueByName("val11"),val11);
	assertEquals(cdt.getValueByName("val12"),val12);
	assertEquals(val11.getCondition(),"temp>4 AND " + val11.getDimension().getPadre().getCondition() );
	assertEquals(val12.getCondition(),"viticoltore() AND " + val12.getDimension().getPadre().getCondition() );
	assertEquals(val21.getCondition(),"hum>10 AND " + val21.getDimension().getPadre().getCondition());
	assertEquals(val22.getCondition(),"vigna() AND " + val22.getDimension().getPadre().getCondition());
	
	
}

}